package puzzle.projecteuler.p100;

import astudy.util.AdvMath;

public class Problem058 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		int m = 2;	//half of side length
		int n = 3;	//number of prime
		while (10*n >= 4*m-3) {
			m ++;
			Integer[] ds = get(m);
			for (int i = 0; i < ds.length; i ++) {
				if (AdvMath.isPrime(ds[i])) {
					n ++;
				}
			}
		}
		System.out.println(2*m-1);
	}
	
	public static Integer[] get(int n) {
		return new Integer[] {
				(n-1)*2 + 4*(n-1)*(n-2) + 1,
				(n-1)*4 + 4*(n-1)*(n-2) + 1,
				(n-1)*6 + 4*(n-1)*(n-2) + 1,
				(n-1)*8 + 4*(n-1)*(n-2) + 1
		};
	}

}
